import plotly_express as px
import plotly.graph_objects as go
import numpy as np

x = np.arange(0, np.pi * 2, 0.05)
y1 = np.sin(x)
y2 = np.cos(x)


# 创建图形对象
fig = go.Figure()

# 添加 sin(x) 曲线
fig.add_trace(
    go.Scatter(
        x=x,
        y=y1,
        mode="lines",
        name="sin(x)",
        line=dict(color="blue"),
    )
)

# 添加 cos(x) 曲线
fig.add_trace(
    go.Scatter(
        x=x,
        y=y2,
        mode="lines",
        name="cos(x)",
        line=dict(color="red"),
    )
)

# 更新布局
fig.update_layout(
    title="sin(x) 和 cos(x) 函数图像",
    xaxis_title="x",
    yaxis_title="y",
    xaxis=dict(
        tickmode="array",
        tickvals=[0, np.pi / 2, np.pi, 3 * np.pi / 2, 2 * np.pi],
        ticktext=["0", "π/2", "π", "3π/2", "2π"],
    ),
)

# 显示图形
fig.show()
